package com.medical.manage.controller;

import com.medical.common.core.domain.Result;
import com.medical.common.core.web.controller.BaseController;
import com.medical.common.log.annotation.Log;
import com.medical.common.log.enums.BusinessType;
import com.medical.common.security.annotation.RequiresPermissions;
import com.medical.manage.domain.Medicine;
import com.medical.manage.service.MedicineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 药品详情Controller
 *
 * @author medical
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/medicine")
public class MedicineController extends BaseController {

    @Autowired
    private MedicineService medicineService;

    /**
     * 查询药品详情列表
     */
    @RequiresPermissions("manage:medicine:list")
    @GetMapping("/list")
    public Result list(Medicine medicine){
        startPage();
        List<Medicine> list = medicineService.list();
        return getDataTable(list);
    }




    /**
     * 新增药品详情
     */
    @RequiresPermissions("manage:medicine:add")
    @Log(title = "药品详情", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Medicine medicine){
        medicineService.save(medicine);
        return success();
    }

    /**
     * 修改药品详情
     */
    @RequiresPermissions("manage:medicine:edit")
    @Log(title = "药品详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Medicine medicine){
        medicineService.updateById(medicine);
        return success();
    }


    /**
     * 删除药品详情
     */
    @RequiresPermissions("manage:medicine:remove")
    @Log(title = "药品详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{medicineIds}")
    public Result remove(@PathVariable Long[] medicineIds){
        List<Long> list = Arrays.asList(medicineIds);
        medicineService.removeBatchByIds(list);
        return success();
    }


}
